import time
import allure
import pytest
import requests
import os
from .data import load_deviceAdddata
basedir=os.path.dirname(__file__)
filepath=os.path.join(basedir,"testCase/deviceAdd.json")
@allure.epic("添加设备接口")
class TestDeviceAdd:
    def setup_class(self):
        self.session=requests.session()
        self.session.post("http://127.0.0.1:8000/login",data={"username":"user10","password":"111111"})
        print("添加设备接口测试开始：",time.strftime("%Y-%m-%d-%H:%M:%S"))
    def teardown_class(self):
        self.session.close()
        print("添加设备接口测试结束：",time.strftime("%Y-%m-%d-%H:%M:%S"))
    @pytest.mark.parametrize("testCase,device_id,name,msg,status_code",load_deviceAdddata(filepath))
    @allure.title("{testCase}")
    def test_deviceAdd(self,testCase,device_id,name,msg,status_code):
        self.url="http://127.0.0.1:8000/devices/add"
        data={
            "device_id":device_id,
            "name":name
        }
        responses=self.session.post(self.url,data=data)
        assert status_code==responses.status_code
        assert msg in responses.url

